package com.pm.controller.task;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.pm.common.Response;
import com.pm.common.annotation.MyLog;
import com.pm.common.annotation.UserLoginToken;
import com.pm.common.exception.ExpCodeState;
import com.pm.entity.po.task.TaskFile;
import com.pm.service.task.TaskFileService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "目标任务进度文件上传")
@UserLoginToken
@RestController
@RequestMapping("/taskFile")
public class TaskFileController {
	@Autowired
	TaskFileService taskService;

	@ApiOperation("新增接口")
	@PostMapping("/add")
	@ResponseBody
	@MyLog(value = "新增目标任务进度文件")
	public Response<Integer> add(TaskFile task) {
		Response<Integer> response = null;
		Integer result = taskService.add(task);
		if (result > 0) {
			response = new Response<>(ExpCodeState.add_data_success, result);
		} else {
			response = new Response<>(ExpCodeState.add_data_failed);
		}
		return response;
	}


	@ApiOperation("删除接口")
	@PostMapping("/remove")
	@ResponseBody
	@MyLog(value = "删除目标任务进度文件")
	public Response<Integer> remove(TaskFile task) {
		Response<Integer> response = null;
		Integer result = taskService.remove(task);
		if (result > 0) {
			response = new Response<>(ExpCodeState.remove_data_success, result);
		} else {
			response = new Response<>(ExpCodeState.remove_data_failed);
		}
		return response;
	}

	@ApiOperation("单个对象查询接口")
	@PostMapping("/load")
	@ResponseBody
	public Response<TaskFile> load(TaskFile task) {
		Response<TaskFile> response = null;
		TaskFile result = taskService.load(task);
		response = new Response<TaskFile>(ExpCodeState.query_data_success, result);
		return response;
	}

	@ApiOperation("全部列表查询接口")
	@PostMapping("/getList")
	@ResponseBody
	public Response<List<TaskFile>> getList(TaskFile task) {
		List<TaskFile> result = taskService.getList(task);
		Response<List<TaskFile>> res = new Response<List<TaskFile>>(ExpCodeState.query_data_success, result);
		return res;
	}

}
